package com.example.administrator.zhongyichou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.zhongyichou.net.protocol.MyBankProtocol;
import com.example.administrator.zhongyichou.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lichenyu on 2017/11/30.
 * 描述：
 */

public class MyBankListAdapter extends ListBaseAdapter {

    private OnDeleteClick onDeleteClick;

    public MyBankListAdapter(Context mContext, List list) {
        super(mContext, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.my_bank_list_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final MyBankProtocol.DataBean bean = (MyBankProtocol.DataBean) getData(position);
        holder.txtName.setText(bean.getBank_name());
        holder.txtZhihang.setText(bean.getBank_branch());
        holder.txtBankId.setText(bean.getCard_num().substring(4) + " **** **** " + bean.getCard_num().substring(bean.getCard_num().length() - 4, bean.getCard_num().length()));
        holder.imgDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onDeleteClick.onDelete();
            }
        });
        return convertView;
    }

    public interface OnDeleteClick{
        void onDelete();
    }

    public void setOnDeleteClick(OnDeleteClick onDeleteClick){
        this.onDeleteClick=onDeleteClick;
    }

    static class ViewHolder {
        @BindView(R.id.txt_name)
        TextView txtName;
        @BindView(R.id.txt_zhihang)
        TextView txtZhihang;
        @BindView(R.id.img_delete)
        ImageView imgDelete;
        @BindView(R.id.txt_bank_id)
        TextView txtBankId;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
